package com.andy.qi.conf;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;

import com.corundumstudio.socketio.Configuration;
import com.corundumstudio.socketio.SocketIOServer;
import com.corundumstudio.socketio.annotation.SpringAnnotationScanner;

@org.springframework.context.annotation.Configuration
public class SocketIOConfig {
    
    @Autowired private RoomServerConf config;
    
    @Bean
    public SocketIOServer socketIOServer() {
        System.out.println("==================" + config.getClientIp());
        System.out.println("==================" + config.getClientPort());
        Configuration configuration = new Configuration();
//        configuration.setHostname(config.getClientIp());
        configuration.setPort(config.getClientPort());
        
//        //该处可以用来进行身份验证
//        configuration.setAuthorizationListener(new AuthorizationListener() {
//            @Override
//            public boolean isAuthorized(HandshakeData data) {
//                //http://localhost:8081?username=test&password=test
//                //例如果使用上面的链接进行connect，可以使用如下代码获取用户密码信息，本文不做身份验证
////              String username = data.getSingleUrlParam("username");
////              String password = data.getSingleUrlParam("password");
//                return true;
//            }
//        });
        
        return new SocketIOServer(configuration);
    }
    
    @Bean
    public SpringAnnotationScanner springAnnotationScanner(SocketIOServer socketServer) {
        return new SpringAnnotationScanner(socketServer);
    }
    
}
